package com.uzhie.jt808.msg.entity.JT_200;

import com.uzhie.jt808.msg.entity.BitConverter;
import com.uzhie.jt808.msg.entity.IPositionAdditionalItem;

import java.util.HashMap;
import java.util.Map;

/**
 *
 * 1078 报警扩展,通道信号丢失判断
 * Created by lilongfei on 2018/7/31.
 */
public class Media_Dropout implements IPositionAdditionalItem {

    int channel;

    Map<Integer,Integer> status;

    public Map<Integer, Integer> getStatus() {
        return status;
    }

    public void setStatus(Map<Integer, Integer> status) {
        this.status = status;
    }

    public int getChannel() {
        return channel;
    }

    public void setChannel(int channel) {
        this.channel = channel;
    }

    @Override
    public int getAdditionalId() {
        return 0x016;
    }

    @Override
    public byte getAdditionalLength() {
        return 0x04;
    }

    @Override
    public byte[] WriteToBytes() {
        return new byte[0];
    }

    @Override
    public void ReadFromBytes(byte[] bytes) {
        status = new HashMap<>();
        for (int i=0  ;i<32;i ++){
            byte t = (byte) ((BitConverter.ToUInt32(bytes,0) >> (i)) & 0x0001);
            if (t == 1) status.put(i, (int) t);
//            System.out.println("当前通道:" + i + ", 摄像头信号 : " + (t==0 ? "正常":"丢失"));
        }
        setChannel(BitConverter.ToUInt32(bytes,0));
    }

    public static void main (String[] arge){
        Media_Dropout order = new Media_Dropout();
        order.ReadFromBytes(BitConverter.GetBytes(3));
    }
}
